import { reqCategory } from '@/api/categoryList'
import type { IResCategoryData, IResCategoryDataList, IResGlobal } from '@/types/categoryList'
import { defineStore } from 'pinia'

// 创建store
export const useCategoryStore = defineStore('categoryStore', {
  state: (): IResCategoryDataList => {
    return {
      YXJSONArray: {},
      YXJSONObject: {},
      data: {} as IResCategoryData,
      global: {} as IResGlobal
    }
  },
  actions: {
    async getCategoryList () {
        const res = await reqCategory()
        // 解构数据
        const {YXJSONArray, YXJSONObject, data, global } = res.data
        // 进行赋值
        this.YXJSONArray = YXJSONArray
        this.YXJSONObject = YXJSONObject
        this.data = data
        this.global = global
    }
  }
})
